package cn.com.code.design;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author zhengpei
 * @date 2021/9/28
 */
public class LoginSsoDecorator extends SsoInterceptor {

  private static Map<String, String> authMap = new ConcurrentHashMap<>();

  static {
    authMap.put("huahua","queryUserInfo");
    authMap.put("xiaoxiao","queryUserInfo");
  }

  @Override
  public boolean preHandle(String request, String response, Object handler) {
    String ticket = request.substring(1,8);
    boolean success = "success".equals(ticket);
    if(!success){
      return false;
    }
    String userId = request.substring(8);
    String method = authMap.get(userId);

    return "queryUserInfo".equals(method);
  }
}
